package org.teamh.connection.handler;

import org.teamh.game.Start;
import org.teamh.gui.Event;

public class ChatHandler extends MasterHandler {
	
	public ChatHandler(Start start) {
		super(start);
	}

	public boolean handleMsg(String line) {
		if (line.startsWith("MSG")) {
			
			String[] str = line.split(" ");
			String message = "";
			
			int i = 3;
			while (i < str.length) {
				message += (" " + str[i]);
				i++;
			}

			if (str[2].contains("ALL")) {
				start.getGui().addEvent(new Event("chat", str[1] + ": " + message, "#000"));
			} else if (str[2].contains("YOU")) {
				start.getGui().addEvent(new Event("chat", str[1] + " -> " + start.getModel().getPlayerName() + ": " + message, "#00f"));
			} else if (str[2].contains("TEAM")) {
				start.getGui().addEvent(new Event("chat", str[1] + " -> " + start.getModel().getTeam() + ": " + message, "#f00"));
			} 
			
			return true;
		} else {
			return false;
		}
	}

}
